 /**
 * @file tkl_endpoint_register.h
 * @brief Common process - endpoint register
 * @version 1.0.0
 * @date 2021-04-21
 *
 * @copyright Copyright 2021-2022 Tuya Inc. All Rights Reserved.
 *
 */

#ifndef __TKL_ENDPOINT_REGISTER_H__
#define __TKL_ENDPOINT_REGISTER_H__


#ifdef __cplusplus
    extern "C" {
#endif

#include "tuya_zigbee_stack.h"
#include "tuya_cloud_types.h"

/* 
 * attribute instantiation structure 
*/
typedef struct {
    UINT16_T        attr_id;    ///< attributes id
    ZG_ATTR_TYPE_E  type;       ///< attributes data type
    UINT8_T         size;       ///< length of attributes value
    UINT8_T         mask;       ///< attributes mask
    UINT8_T         flag;       ///< indicates whether ATT supports the scene
    VOID_T          *value;     ///< the default value of attribute
} TKL_ATTR_T;

/* 
 * cluster instantiation structure 
*/
typedef struct {
    UINT16_T    cluster_id;     ///< cluster id, see ZG_CLUSTER_ID_E
    TKL_ATTR_T  *attr_list;     ///< a list of attributes definitions
    UINT8_T     attr_sums;      ///< how many attributes does a cluster have
} TKL_CLUSTER_T;

/*
 * Zigbee cluster triplet structure
*/
typedef struct {
    UINT8_T  ep_id;             ///< endpoint id
    UINT8_T  is_server;         ///< cluster is server or client
    UINT16_T cluster_id;        ///< cluster id,see ZG_CLUSTER_ID_E
} TKL_CLUSTER_TRIPLET_T;

/* 
 * endpoint instantiation structure 
*/
typedef struct {
    UINT8_T         ep_id;                  ///< endpoint id
    ZG_PROFILE_ID_E profile;                ///< profile of endpoint
    ZG_DEV_ID_E     dev_id;                 ///< device id of endpoint
    UINT8_T         server_cluster_sums;    ///< the number of clusters on the server side
    TKL_CLUSTER_T   *server_cluster_list;   ///< server cluster
    UINT8_T         client_cluster_sums;    ///< the number of clusters on the client side
    TKL_CLUSTER_T   *client_cluster_list;   ///< client cluster
} TKL_ENDPOINT_T;

/*
 * device version definitions
*/
typedef enum {
    DEV_VER_ZHA = 0x00,         ///< Zigbee HA
    DEV_VER_ZG30,               ///< Zigbee3.0
    DEV_VER_ZLL,                ///< Zigbee Light link
}TKL_DEV_VER_E;

/**
 * @brief get the total number of endpoints
 *
 * @param[in] 
 * @return endpoint number
 */
UINT8_T tkl_zg_endpoint_count_get(VOID_T);

/**
 * @brief endpoint used by dynamically registered uplayer,
 * only be called once in the initialization process.
 *
 * @param[in] ep_desc: point to endpoint list
 * @param[in] sums:    endpoint number
 * @return  0: success  Other: fail
 */
OPERATE_RET tkl_zg_endpoint_register(CONST TKL_ENDPOINT_T *ep_desc, UINT8_T sums);

/**
 * @brief match cluster on endpoint
 *
 * @param[in] triplet: point to cluster triplet
 * @return  TRUE/ FALSE
 */
BOOL_T tkl_zg_match_cluster(TKL_CLUSTER_TRIPLET_T *triplet);

/**
 * @brief get attribute details
 *
 * @param[in] ep_id:   endpoint id
 * @param[in] attr_id: attribute id
 * @param[out] out_attr: attribute details output
 * @return  TRUE/ FALSE
 */
BOOL_T tkl_zg_attr_get(TKL_CLUSTER_TRIPLET_T *triplet, UINT16_T attr_id, TKL_ATTR_T *out_attr);

/**
 * @brief [TUYA_WEAK_ATTRIBUTE function],set device version according to ep_id
 * 
 * @param[in] ep_id 
 * @return TKL_DEV_VER_T 
 */
TKL_DEV_VER_E tkl_zg_endpoint_to_device_version(UINT8_T ep_id);

#ifdef __cplusplus
}
#endif

#endif
